load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//build:STRINGER.bzl", "stringer")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "cli",
    srcs = [
        "auth.go",
        "auto_decrypt_fs.go",
        "cert.go",
        "cli.go",
        "client_url.go",
        "context.go",
        "convert_url.go",
        "debug.go",
        "debug_check_store.go",
        "debug_job_cleanup.go",
        "debug_job_trace.go",
        "debug_list_files.go",
        "debug_logconfig.go",
        "debug_merge_logs.go",
        "debug_recover_loss_of_quorum.go",
        "debug_reset_quorum.go",
        "debug_send_kv_batch.go",
        "debug_synctest.go",
        "declarative_corpus.go",
        "declarative_print_rules.go",
        "decode.go",
        "demo.go",
        "demo_telemetry.go",
        "doctor.go",
        "env.go",
        "examples.go",
        "flags.go",
        "flags_util.go",
        "gen.go",
        "haproxy.go",
        "import.go",
        "init.go",
        "log_flags.go",
        "mt.go",
        "mt_cert.go",
        "mt_start_sql.go",
        "node.go",
        "nodelocal.go",
        "prefixer.go",
        "rpc_client.go",
        "rpc_node_shutdown.go",
        "sql_client.go",
        "sql_shell_cmd.go",
        "sqlfmt.go",
        "start.go",
        "start_jemalloc.go",
        "start_unix.go",
        "start_windows.go",
        "statement_bundle.go",
        "statement_diag.go",
        "testutils.go",
        "tsdump.go",
        "userfile.go",
        "zip.go",
        "zip_cluster_wide.go",
        "zip_cmd.go",
        "zip_helpers.go",
        "zip_per_node.go",
        "zip_table_registry.go",
        "zip_upload.go",
        ":gen-keytype-stringer",  # keep
    ],
    # keep
    cdeps = [
        "//c-deps:libjemalloc",
    ],
    cgo = True,
    # keep
    clinkopts = select({
        "@io_bazel_rules_go//go/platform:android": [
            "-lrt -lm -lpthread",
        ],
        "@io_bazel_rules_go//go/platform:dragonfly": [
            "-lm",
        ],
        "@io_bazel_rules_go//go/platform:freebsd": [
            "-lm",
        ],
        "@io_bazel_rules_go//go/platform:linux": [
            "-lrt -lm -lpthread",
        ],
        "//conditions:default": [],
    }),
    # keep
    cppopts = [
        "-DJEMALLOC_NO_DEMANGLE",
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/cli",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/build",
        "//pkg/cli/clicfg",
        "//pkg/cli/clientflags",
        "//pkg/cli/clienturl",
        "//pkg/cli/clierror",
        "//pkg/cli/clierrorplus",
        "//pkg/cli/cliflagcfg",
        "//pkg/cli/cliflags",
        "//pkg/cli/clisqlcfg",
        "//pkg/cli/clisqlclient",
        "//pkg/cli/clisqlexec",
        "//pkg/cli/clisqlshell",
        "//pkg/cli/democluster",
        "//pkg/cli/exit",
        "//pkg/cli/syncbench",
        "//pkg/cloud",
        "//pkg/cloud/cloudpb",
        "//pkg/cloud/impl:cloudimpl",
        "//pkg/cloud/userfile",
        "//pkg/clusterversion",
        "//pkg/config",
        "//pkg/docs",
        "//pkg/geo/geos",
        "//pkg/gossip",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/keys",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver",
        "//pkg/kv/kvserver/gc",
        "//pkg/kv/kvserver/kvserverpb",
        "//pkg/kv/kvserver/kvstorage",
        "//pkg/kv/kvserver/liveness/livenesspb",
        "//pkg/kv/kvserver/loqrecovery",
        "//pkg/kv/kvserver/loqrecovery/loqrecoverypb",
        "//pkg/kv/kvserver/rditer",
        "//pkg/kv/kvserver/stateloader",
        "//pkg/raft/raftpb",
        "//pkg/roachpb",
        "//pkg/rpc",
        "//pkg/security",
        "//pkg/security/certnames",
        "//pkg/security/clientsecopts",
        "//pkg/security/securitytest",
        "//pkg/security/username",
        "//pkg/server",
        "//pkg/server/authserver",
        "//pkg/server/debug",
        "//pkg/server/pgurl",
        "//pkg/server/profiler",
        "//pkg/server/serverctl",
        "//pkg/server/serverpb",
        "//pkg/server/status",
        "//pkg/server/status/statuspb",
        "//pkg/server/telemetry",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/sql",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/catalogkeys",
        "//pkg/sql/catalog/descbuilder",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/doctor",
        "//pkg/sql/execinfrapb",
        "//pkg/sql/lexbase",
        "//pkg/sql/parser",
        "//pkg/sql/parser/statements",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/protoreflect",
        "//pkg/sql/row",
        "//pkg/sql/rowenc",
        "//pkg/sql/schemachanger/corpus",
        "//pkg/sql/schemachanger/scop",
        "//pkg/sql/schemachanger/scpb",
        "//pkg/sql/schemachanger/scplan",
        "//pkg/sql/sem/builtins",
        "//pkg/sql/sem/catconstants",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sqlstats",
        "//pkg/sql/stats",
        "//pkg/storage",
        "//pkg/storage/enginepb",
        "//pkg/storage/fs",
        "//pkg/testutils/bazelcodecover",
        "//pkg/testutils/serverutils",
        "//pkg/ts",
        "//pkg/ts/catalog",
        "//pkg/ts/tspb",
        "//pkg/ts/tsutil",
        "//pkg/upgrade/upgrades",
        "//pkg/util",
        "//pkg/util/buildutil",
        "//pkg/util/cgroups",
        "//pkg/util/cidr",
        "//pkg/util/encoding",
        "//pkg/util/envutil",
        "//pkg/util/flagutil",
        "//pkg/util/grpcutil",
        "//pkg/util/hlc",
        "//pkg/util/httputil",
        "//pkg/util/humanizeutil",
        "//pkg/util/ioctx",
        "//pkg/util/iterutil",
        "//pkg/util/keysutil",
        "//pkg/util/log",
        "//pkg/util/log/channel",
        "//pkg/util/log/logconfig",
        "//pkg/util/log/logcrash",
        "//pkg/util/log/logflags",
        "//pkg/util/log/logpb",
        "//pkg/util/log/severity",
        "//pkg/util/netutil/addr",
        "//pkg/util/protoutil",
        "//pkg/util/retry",
        "//pkg/util/sdnotify",
        "//pkg/util/stop",
        "//pkg/util/strutil",
        "//pkg/util/syncutil",
        "//pkg/util/sysutil",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/tracing/tracingpb",
        "//pkg/util/tracing/zipper",
        "//pkg/util/uuid",
        "//pkg/workload",
        "//pkg/workload/bank",
        "//pkg/workload/bulkingest",
        "//pkg/workload/cli",
        "//pkg/workload/debug",
        "//pkg/workload/examples",
        "//pkg/workload/insights",
        "//pkg/workload/kv",
        "//pkg/workload/movr",
        "//pkg/workload/sqlstats",
        "//pkg/workload/tpcc",
        "//pkg/workload/tpch",
        "//pkg/workload/ttlbench",
        "//pkg/workload/ttllogger",
        "//pkg/workload/workloadsql",
        "//pkg/workload/ycsb",
        "@com_github_cockroachdb_apd_v3//:apd",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_errors//hintdetail",
        "@com_github_cockroachdb_errors//oserror",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_pebble//:pebble",
        "@com_github_cockroachdb_pebble//objstorage/remote",
        "@com_github_cockroachdb_pebble//tool",
        "@com_github_cockroachdb_pebble//vfs",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_cockroachdb_ttycolor//:ttycolor",
        "@com_github_dustin_go_humanize//:go-humanize",
        "@com_github_fsnotify_fsnotify//:fsnotify",
        "@com_github_gogo_protobuf//jsonpb",
        "@com_github_jackc_pgconn//:pgconn",
        "@com_github_jackc_pgtype//:pgtype",
        "@com_github_kr_pretty//:pretty",
        "@com_github_marusama_semaphore//:semaphore",
        "@com_github_mattn_go_isatty//:go-isatty",
        "@com_github_mozillazg_go_slugify//:go-slugify",
        "@com_github_spf13_cobra//:cobra",
        "@com_github_spf13_cobra//doc",
        "@com_github_spf13_pflag//:pflag",
        "@in_gopkg_yaml_v2//:yaml_v2",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//codes",
        "@org_golang_google_grpc//status",
        "@org_golang_x_sync//errgroup",
    ] + select({
        "@io_bazel_rules_go//go/platform:aix": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:android": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:darwin": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:dragonfly": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:freebsd": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:illumos": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:ios": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:js": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:linux": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:netbsd": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:openbsd": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:plan9": [
            "@org_golang_x_sys//unix",
        ],
        "@io_bazel_rules_go//go/platform:solaris": [
            "@org_golang_x_sys//unix",
        ],
        "//conditions:default": [],
    }),
)

go_test(
    name = "cli_test",
    size = "large",
    srcs = [
        "auto_decrypt_fs_test.go",
        "cert_test.go",
        "cli_debug_test.go",
        "cli_test.go",
        "convert_url_test.go",
        "debug_check_store_test.go",
        "debug_job_trace_test.go",
        "debug_list_files_test.go",
        "debug_merge_logs_test.go",
        "debug_recover_loss_of_quorum_test.go",
        "debug_send_kv_batch_test.go",
        "debug_test.go",
        "declarative_corpus_test.go",
        "declarative_print_rules_test.go",
        "decode_test.go",
        "demo_locality_test.go",
        "demo_test.go",
        "doctor_test.go",
        "flags_test.go",
        "gen_test.go",
        "haproxy_test.go",
        "import_test.go",
        "log_flags_test.go",
        "main_test.go",
        "node_test.go",
        "nodelocal_test.go",
        "prefixer_test.go",
        "sql_client_test.go",
        "sqlfmt_test.go",
        "start_linux_test.go",
        "start_test.go",
        "statement_bundle_test.go",
        "statement_diag_test.go",
        "tsdump_test.go",
        "userfiletable_test.go",
        "workload_test.go",
        "zip_helpers_test.go",
        "zip_per_node_test.go",
        "zip_table_registry_test.go",
        "zip_tenant_test.go",
        "zip_test.go",
        "zip_upload_test.go",
    ],
    data = glob(["testdata/**"]),
    embed = [":cli"],
    exec_properties = select({
        "//build/toolchains:is_heavy": {"test.Pool": "large"},
        # For the benefit of TestDebugCheckStore. That test is skipped under
        # race/deadlock, so the "default" configuration is higher than the
        # "is_heavy" configuration.
        "//conditions:default": {"test.Pool": "heavy"},
    }),
    shard_count = 16,
    deps = [
        "//pkg/base",
        "//pkg/build",
        "//pkg/ccl/backupccl",
        "//pkg/cli/clicfg",
        "//pkg/cli/clienturl",
        "//pkg/cli/clierror",
        "//pkg/cli/clierrorplus",
        "//pkg/cli/cliflags",
        "//pkg/cli/clisqlcfg",
        "//pkg/cli/clisqlclient",
        "//pkg/cli/clisqlexec",
        "//pkg/cli/democluster",
        "//pkg/cli/exit",
        "//pkg/cloud",
        "//pkg/clusterversion",
        "//pkg/gossip",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/jobs/jobstest",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/kvclient/kvtenant",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver",
        "//pkg/kv/kvserver/liveness",
        "//pkg/kv/kvserver/liveness/livenesspb",
        "//pkg/kv/kvserver/loqrecovery",
        "//pkg/kv/kvserver/loqrecovery/loqrecoverypb",
        "//pkg/kv/kvserver/stateloader",
        "//pkg/roachpb",
        "//pkg/security/clientsecopts",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/security/username",
        "//pkg/server",
        "//pkg/server/serverpb",
        "//pkg/server/status",
        "//pkg/server/status/statuspb",
        "//pkg/settings/cluster",
        "//pkg/sql",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/isql",
        "//pkg/sql/protoreflect",
        "//pkg/sql/sem/catconstants",
        "//pkg/storage",
        "//pkg/storage/fs",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/jobutils",
        "//pkg/testutils/listenerutil",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/skip",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/testcluster",
        "//pkg/ts/tspb",
        "//pkg/util",
        "//pkg/util/ioctx",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/log/logconfig",
        "//pkg/util/log/logpb",
        "//pkg/util/netutil/addr",
        "//pkg/util/protoutil",
        "//pkg/util/randutil",
        "//pkg/util/stop",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/uuid",
        "//pkg/workload/examples",
        "@com_github_cockroachdb_datadriven//:datadriven",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_pebble//vfs",
        "@com_github_google_pprof//profile",
        "@com_github_pmezard_go_difflib//difflib",
        "@com_github_spf13_cobra//:cobra",
        "@com_github_spf13_pflag//:pflag",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
    ],
)

stringer(
    name = "gen-keytype-stringer",
    src = "flags_util.go",
    additional_args = ["--stringtovaluemapname=_keyTypes"],
    typ = "keyType",
)

filegroup(
    name = "interactive_tests",
    srcs = glob(
        ["interactive_tests/**"],
    ),
    visibility = ["//visibility:public"],
)

disallowed_imports_test(
    "cli",
    disallowed_list = [
        # TODO(#81375)
        #"//pkg/security/securitytest",
        "//pkg/sql/randgen",
    ],
    disallowed_prefixes = [
        # TODO(#81375)
        #"pkg/testutils",
    ],
)
